package com.hyh.fireworks.web;


import com.hyh.fireworks.common.result.AjaxResult;
import com.hyh.fireworks.common.result.CommonPage;
import com.hyh.fireworks.entity.Posts;
import com.hyh.fireworks.service.IPostsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author summerday
 * @since 2020-11-07
 */

@Api(tags = "文章posts接口")
@RestController
@RequestMapping("/posts")
public class PostsController extends BaseController {


    @Resource
    IPostsService postsService;

    @GetMapping("/page")
    @ApiOperation("分页查询文章")
    public AjaxResult pageList(@RequestParam(value = "current", defaultValue = "1") Long current,
                               @RequestParam(value = "pageSize", defaultValue = "5") Long pageSize) {
        CommonPage<Posts> postsCommonPage = postsService.pageList(current, pageSize);
        return AjaxResult.ok(postsCommonPage);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据文章id查询文章信息")
    public AjaxResult getPostById(@PathVariable("id") Long id){
        Posts post = postsService.getById(id);
        return AjaxResult.ok(post);
    }
}

